#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define i128 __int128
#define mem(x) memset(x,0,sizeof(x))
#define endl "\n"
#define printYes cout << "Yes\n"
#define printYES cout << "YES\n"
#define printNo cout << "No\n"
#define printNO cout << "NO\n"
#define lowbit(x) ((x)&(-(x)))
#define pb push_back
#define mkp make_pair
#define pii pair<int,int>
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define rep(i,j,k) for (int i=(j);i<=(k);i++)
#define per(i,j,k) for (int i=(j);i>=(k);i--)
#define pcnt(x) __builtin_popcount(x)
mt19937_64 rnd(0);
template<class T>void chkmin(T&x,T y){x=min(x,y);}
template<class T>void chkmax(T&x,T y){x=max(x,y);}

const ll inf=1000000000000000000; 
//const ll inf=1000000000;
//const ll mod=998244353;
//const ll mod=1000000007;

const int N=500005;
int n,m; 
int a[N],b[N];
ull c[N];
vector<pii>t[N];
bool vis[N],used[N];
int id[N],fa[N];
ull val[N];
vector<int>st;

void dfs(int x,int f,int las)
{
	vis[x]=1,id[x]=las,fa[x]=f,st.pb(x);
	for (pii i:t[x])
	{
		if (i.fi==f) continue;
		if (vis[i.fi]==0) dfs(i.fi,x,i.se);
		else if (used[i.se]==0)
		{
			used[i.se]=1;
			ull v=rnd();
			val[x]^=v,val[i.fi]^=v,c[i.se]=v;
		}
	}
}

ull d[N],p[N];
bool check(int n)
{
	rep(i,0,63) p[i]=0;
	rep(i,1,n)
	{
		ull x=d[i];
		per(j,63,0)
		{
			if (!(x&(1ull<<j))) continue;
			if (!p[j]) 
			{
				p[j]=x;
				break;
			}
			x^=p[j];
		}
		if (!x) return 1;
	}
	return 0;
}

int main()
{
	freopen("graph.in","r",stdin);
	freopen("graph.out","w",stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	cin >> n >> m;
	rep(i,1,m) cin >> a[i] >> b[i];
	rep(i,1,m) t[a[i]].pb(mkp(b[i],i)),t[b[i]].pb(mkp(a[i],i));
	dfs(1,0,0);
	reverse(st.begin(),st.end());
	for (int i:st) val[fa[i]]^=val[i],c[id[i]]=val[i];
	int q;
	cin >> q;
	while (q--)
	{
		int k;
		cin >> k;
		rep(i,0,k-1)
		{
			int x;
			cin >> x;
			d[i+1]=c[x];
		}
		if (check(k)) cout << "NO\n";
		else cout << "YES\n";
	}
	return 0;
}
